<?php
namespace app\admin\validate\user;

use think\Validate;

/**
 * 用户验证
 */
class Account extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'    =>    ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'user_name' => 'require|unique:admin_user',
        'password'  => [
            'require',
        ],
        'phone'     => 'mobile|unique:admin_user',
    ];

    protected $field = [
        'user_name' => '账号',
        'password'  => '密码',
        'phone'     => ' 手机号',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'    =>    '错误信息'
     *
     * @var array
     */
    protected $message = [
        'user_name.require' => '请输入账号',
        'user_name.unique'  => '用户名已存在',
        'password.require'  => '请输入密码',
    ];

    /**
     * 验证场景
     */
    protected $scene = [
        'create' => ['user_name', 'password', 'phone'],
        'edit'   => ['user_name', 'phone'],
    ];

    public function sceneLogin()
    {
        return $this->only(['user_name','password'])->remove('user_name','unique');
    }

}
